package com.zy.aop.excerse1;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * Created by zy on 2015/11/29.
 */
public class PreLoader {
    private final FutureTask<ProductInfo> future = new FutureTask<ProductInfo>(new Callable<ProductInfo>() {
        @Override
        public ProductInfo call() throws Exception {
            ProductInfo productInfo = new ProductInfo();
            productInfo.setName("hello world");
            return productInfo;
        }
    });
    private final Thread thread = new Thread(future);

    public void start() {
        thread.start();
    }

    public ProductInfo get() throws InterruptedException, ExecutionException {
        return future.get();
    }

    public static void main(String[] args) {
        try {
            PreLoader preLoader = new PreLoader();
            preLoader.start();
            ProductInfo productInfo = preLoader.get();
            System.out.println(productInfo.toString());
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
    }
}
